package org.springframework.samples.mvc.basic.security;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import org.springframework.dao.DataAccessException;
import org.springframework.samples.mvc.basic.user.AuthenticationUser;
import org.springframework.samples.mvc.basic.user.AuthenticationUserBusinessService;
import org.springframework.security.access.PermissionEvaluator;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class UserProviderService implements UserDetailsService, Serializable {
	
	private SpringSecurityUserTransformer<AuthenticationUser> transformer = new SpringSecurityUserTransformerImpl();
	private AuthenticationUserBusinessService service = new AuthenticationUserBusinessService();

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException, DataAccessException {
		return transformer.transform(service.findByUsername(username));
	}

}
